package com.bootdo.hjh.dao;

import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.InsertProvider;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.bootdo.hjh.dao.provider.BankCardProvider;
import com.bootdo.hjh.domain.BankCard;

public interface BankCardMapper {
	
	@Insert("insert into bank_card(user_id,card_number,bank_name,card_user_name)"
			+ " values(#{userId},#{cardNumber},#{bankName},#{cardUserName})")
	@Options(useGeneratedKeys=true)
	public Integer addBankCard(BankCard bankCard);
	
	@InsertProvider(type=BankCardProvider.class,method="modifyBankCard")
	public Integer modifyBankCard(BankCard bankCard);
	
	@Update("update bank_card set is_default = 0 where user_id = #{userId}")
	public void updateUserAddressDefaultToNone(Long userId);
	
	@Update("update bank_card set is_default = 1 where user_id = #{userId} and id = #{id}")
	public void updateBankCardDefault(BankCard bankCard);
	
	@Delete("delete from bank_card where id = #{id}")
	public void deleteBankCard(Integer id);
	
	@Select("select * from bank_card where id = #{bankCardId}")
	public BankCard getBankCardById(Integer bankCardId);
	
	@Select("select * from bank_card where user_id = #{userId} order by is_default desc")
	public List<BankCard> getBankCardForAll(Long userId);
	
	
	
	
}
